<?php

namespace App\Modules\Admin\Http\Controllers\Member;

use App\Exceptions\Exception;
use App\Modules\Admin\Http\Controllers\BaseController;
use App\Modules\Admin\Http\Requests\Water\UsersRequest;
use App\Modules\Admin\Services\Member\BuyUserServices;
use App\Modules\Admin\Services\Water\Member\UsersService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class BuyUsersControllers extends BaseController
{
    public function __construct(BuyUserServices $service)
    {
        $this->service = $service;
    }
    public function create(UsersRequest $request): JsonResponse
    {
        return $this->createService($request);
    }

    /**
     *  绑定水机列表
     * @param Request $request
     * @return JsonResponse
     */
    public function getUsersWaterLists(Request $request) : JsonResponse
    {
        $result = $this->service->getUsersWaterLists($request);
        if ($result){
            return $this->successJson($result, $this->service->getError());
        }else{
            return $this->errorJson($this->service->getError());
        }
    }

    /**
     *  获取积分详情列表
     * @param Request $request
     * @return JsonResponse
     */
    public function getIntegraDetailList(Request $request) : JsonResponse
    {
        $result = $this->service->getUsersIntegraDetailLists($request);
        return $this->successJson($result, $this->service->getError());
    }

    /** 绑定水机
     * @param Request $request
     * @return JsonResponse
     * @throws Exception
     */
    public function updateUsersWater(Request $request) : JsonResponse
    {
        $result = $this->service->updateUsersWater($request->all());
        if ($result){
            return $this->successJson($result, $this->service->getError());
        }else{
            return $this->errorJson($this->service->getError());
        }
    }


    /**
     *  变更身份 权限
     * @param Request $request
     * @return JsonResponse
     * @throws Exception
     */
    public function role(Request $request) : JsonResponse
    {
        $result = $this->service->rolesUser($request->all());
        if ($result){
            return $this->successJson($result, "操作成功");
        }else{
            return $this->errorJson($this->service->getError());
        }
    }


}
